# -*- coding: utf-8 -*-
"""
Created on Fri Aug 26 11:04:27 2022

@author: xiong
"""
import hashlib
import time

def sqlPostsTemplate(data,taskid):
    userid =   data["user_id"]
    md5_userid = hashlib.md5(userid.encode(encoding='UTF-8')).hexdigest()

    vcid = hashlib.md5(str(time.time()).encode(encoding='UTF-8')).hexdigest()
    sql = """INSERT INTO gather_facebook_posts
            (vc_id,vc_target_user_id,vc_userid,vc_nickname,vc_username,vc_photo_url,vc_photo_url_local,vc_postid,text_post_content,text_picture_url,text_picture_url_local,vc_reply_count,vc_forward_count,vc_favorites_count,vc_forward_url,vc_forward_title,text_forward_content,vc_forward_user,dt_forward_date,vc_video_url,vc_video_url_local,vc_video_picture_url,vc_video_picture_url_local,dt_pubdate,text_content,dt_gather_time,vc_task_id,vc_task_type,vc_md5,vc_cookie_str,vc_gather_user_id,vc_post_type,vc_fb_dtsg,vc_feedback_id,vc_fb_dtsg_ag,vc_client_type,vc_story_fbid) 
             VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s',
             '%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s',
             '%s','%s','%s','%s','%s','%s','%s')"""%(
            vcid,#vc_id
            md5_userid ,#vc_target_user_id
            data["user_id"],#vc_userid
            data["nick_name"],#vc_nickname
            "",#vc_username
            ",".join(i[0] for i in data["image_url_and_description"]),#vc_photo_url
            ",".join(i[1] for i in data["image_url_and_description"]),#vc_photo_url_local
            data["post_id"],#vc_postid
            data["posts_text"],#text_post_content
            '',#text_picture_url
            '',#text_picture_url_local
            data["comment_num"],#vc_reply_count
            data["share_num"],#vc_forward_count
            data["like_num"],#vc_favorites_count
            '',#vc_forward_url
            '',#vc_forward_title
            '',#text_forward_content
            '',#vc_forward_user
            '',#dt_forward_date
            ",".join(i[0] for i in data["vidio_url"]),#vc_video_url
            ",".join(i[1] for i in data["vidio_url"]),#vc_video_url_local
            '',#vc_video_picture_url
            '',#vc_video_picture_url_local
            '',#dt_pubdate
            '',#text_content
            time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(data["dt_gather_time"])),#dt_gather_time
            taskid,#vc_task_id
            '',#vc_task_type
            hashlib.md5((taskid+data["post_id"]).encode(encoding='UTF-8')).hexdigest(),#vc_md5
            '',#vc_cookie_str
            '',#vc_gather_user_id
            '',#vc_post_type
            '',#vc_fb_dtsg
            '',#vc_feedback_id
            '',#vc_fb_dtsg_ag
            '',#vc_client_type
            data["post_fbid"],#vc_story_fbid
    )
    return sql